import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'

import songDetail from "@/components/song-detail.vue"
import songList from "@/components/song-list.vue"
import searchAll from "@/components/search-all.vue"
import searchSongs from "@/components/search-songs.vue"
Vue.component('song-detail', songDetail);
Vue.component('song-list', songList);
Vue.component('search-all', searchAll);
Vue.component('search-songs', searchSongs);


Vue.prototype.$showToast = function(msg) {
	uni.showToast({
		icon: "none",
		title: msg
	});
}

Vue.prototype.$navigateTo = function(url) {
	uni.navigateTo({
		url,
	});
}

Vue.prototype.$http = function(url, data, method = "GET") {
	const host = "http://localhost:3000";
	return new Promise(function(resolve, reject) {
		const success = function(res) {
			// console.log(res);
			try {
				if (res.data.code === 200) {
					resolve(res.data.data);
				} else {
					reject("error:" + (res.data.errMsg || "返回错误信息字段msg缺失"));
				}
				return;
			} catch (e) {
				reject("except:" + JSON.stringify(e));
			}
		};
		const fail = function(err) {
			reject("fail:" + JSON.stringify(err));
		};
		uni.request({
			sslVerify: false,
			method,
			url: host + url,
			data,
			success,
			fail
		});
	});
}

import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

import lottie from 'lottie-web'

Vue.prototype.$lottie = lottie

const app = new Vue({
	...App
})


app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'

export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif